﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace ProgressTracker.Data.Entities
{
    public class Day
    {
        protected internal virtual ICollection<DayTask> DayTasks { get; set; }

        public virtual int Id { get; set; }
        public virtual DateTime Date { get; set; }
        public virtual string Notes { get; set; }
        public virtual User User { get; set; }

        public Day()
        {
            DayTasks = new List<DayTask>();
        }

        public virtual IEnumerable<Task> Tasks
        {
            get { return DayTasks.Select(x => x.Task); }
        }

        public virtual void UpdateTaskCompleteness(Task task, bool isComplete)
        {
            var dayTask = DayTasks.Where(x => x.Task.Id == task.Id).Single();

            dayTask.TaskComplete = isComplete;
        }
    }
}
